package edu.qhst.resource.utils;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.IOUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * org.apache.tomcat.util.http.fileupload.FileItem 转换 MultipartFile
 *
 */
public class FileItemToMultipartFileConverter {
    public static MultipartFile convert(FileItem fileItem) throws IOException {
        return new org.springframework.mock.web.MockMultipartFile(
                fileItem.getFieldName(),
                fileItem.getName(),
                fileItem.getContentType(),
                IOUtils.toByteArray(fileItem.getInputStream())
        );
    }
}
